import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
import path from "path";
import AutoImport from "unplugin-auto-import/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import Components from "unplugin-vue-components/vite";
import { defineConfig } from "vite";

const timeStamp = new Date().getTime();

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  base: "./",
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },
  server: {
    proxy: {
      "/api": {
        target: "http://192.168.129.129:10103/airobot/",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
    },
    host: "0.0.0.0",
  },
  build: {
    outDir: "robotManage",
    rollupOptions: {
      input: "index.html",
      output: {
        chunkFileNames: `assets/js/[name]-[hash]-${timeStamp}.js`,
        entryFileNames: `assets/js/[name]-[hash]-${timeStamp}.js`,
        assetFileNames: `assets/[ext]/[name]-[hash]-${timeStamp}.[ext]`,
        manualChunks: {
          elementPlus: ["element-plus"],
        },
      },
    },
  },
});
